<template>
    <el-dialog
    title="修改"
    :visible.sync="dialogFormVisible"
    @close="closeDialog"
  >
    <el-form
      ref="dataForm"
      :model="carFrom"
      label-position="left"
      label-width="90px"
      style="width: 400px; margin-left: 50px"
    >
    <el-form-item label="车辆类型" prop="type">
        <el-radio-group v-model="carFrom.carType">
          <el-radio label="小型车"></el-radio>
          <el-radio label="SUV"></el-radio>
        </el-radio-group>
     </el-form-item>
    <el-form-item label="车牌号" prop="num" style="width: 300px;">
        <el-input v-model="carFrom.carNum"></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="adress" style="width: 500px;">
      <el-input type="textarea" v-model="carFrom.address"></el-input>
    </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="closeDialog"> 取消 </el-button>
      <el-button type="primary" @click="updateData()"> 提交 </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { updateCarInfo } from '@/api/index';
export default {
    name:'CarEdit',
    data() {
        return {
            dialogFormVisible: false,
            carFrom:{
                carId:'',
                carNum:'',
                carType:'',
                address:'',
            },
        }
    },
    methods: {
        init(data) {
            console.log(data);
            this.dialogFormVisible = true;
            this.carFrom.carId = data.carId;
            this.carFrom.carNum = data.carNum;
            this.carFrom.carType = data.carType;
            this.carFrom.address = data.address;
        },
        closeDialog() {
            this.dialogFormVisible = false;
            this.$refs["dataForm"].clearValidate();
            },
            updateData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
            updateCarInfo(this.carFrom).then((res) => {
            if (res.success) {
              this.closeDialog();
              this.$emit('fatherMethod');
              this.$notify({
                title: "Success",
                message: "更新成功",
                type: "success",
                duration: 2000,
              });
            } else {
              this.closeDialog();
              this.$notify({
                title: "failed",
                message: res.errorMsg,
                type: "error",
                duration: 2000,
              });
            }
          });
        }
      });
    },
  },
};
</script>

<style>

</style>